package com.zx.map.dao.impl;

import com.zx.map.dao.CreditRepayInfoDao;
import com.zx.map.dao.mapper.CreditRepayInfoMapper;
import com.zx.map.dao.model.CreditRepayInfo;
import com.zx.map.dao.model.CreditRepayInfoExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 14-3-1
 * Time: 上午10:54
 * To change this template use File | Settings | File Templates.
 */
@Component("creditRepayInfoDao")
public class CreditRepayInfoImpl implements CreditRepayInfoDao {

    @Autowired
    private CreditRepayInfoMapper mapper;

    /**
     * 新增
     */
    public String add(CreditRepayInfo creditRepayInfo) throws DataAccessException {
        creditRepayInfo.setCreateDate(new Date());
        int column = mapper.insert(creditRepayInfo);
        if (column != 1) {
            throw new RuntimeException("");
        }
        return creditRepayInfo.getPaycardId().toString();
    }

    /**
     * 修改
     * @param creditRepayInfo
     * @return
     * @throws DataAccessException
     */
    public String update(CreditRepayInfo creditRepayInfo) throws DataAccessException {
        int column = mapper.updateByPrimaryKeySelective(creditRepayInfo);
        if (column != 1) {
            throw new RuntimeException("");
        }
        return creditRepayInfo.getPaycardId().toString();
    }

    /**
     * 删除
     */
    public void delete(CreditRepayInfo creditRepayInfo) throws DataAccessException {
        int column = mapper.deleteByPrimaryKey(creditRepayInfo.getPaycardId());
        if (column != 1) {
            throw new RuntimeException("");
        }
    }

	/**
	 * 
	 */
	public List<CreditRepayInfo> getListByExample(CreditRepayInfoExample example)
			throws DataAccessException {
		return mapper.selectByExample(example); 
	}
	/**
     * 分页查找
     */
	public List<CreditRepayInfo> getPageByExample(int pageSize, int pageBegin,
			CreditRepayInfoExample example) throws DataAccessException 
			{
		return mapper.getPageByModel(pageSize, pageBegin, example);  
	}

	@Override
	public int countListByExample(CreditRepayInfoExample example) {
		return mapper.countByExample(example);
	}

	@Override
	public CreditRepayInfo selectByPrimaryKey(Integer key)
			throws DataAccessException {
		return mapper.selectByPrimaryKey(key);
	}
}
